package models

import (
	"gitee.com/tsingeye/FreeEhome/config"
	"gitee.com/tsingeye/FreeEhome/tools"
	"os"
	"path/filepath"
)

//文件路径列表
func FileList() (replyData map[string]interface{}) {
	fileList := getFileList(tools.GetAbsPath() + "image")
	replyData = map[string]interface{}{
		"errCode":  config.EHomeSuccessOK,
		"errMsg":   config.HTTPCodeMap[config.EHomeSuccessOK],
		"fileList": fileList,
	}

	return
}

//filepath包实现了兼容各个操作系统的文件路径实用操作方法
func getFileList(dirname string) (fileList []string) {
	filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
		if !info.IsDir() {
			fileList = append(fileList, path)
		}
		return nil
	})

	return
}
